using System;
using UnityEngine;

public class GaussDistribution
{
	public static float[] standardNormalTable = new float[310]
	{
		0f,
		0.00399f,
		0.00798f,
		0.01197f,
		0.01595f,
		0.01994f,
		0.02392f,
		0.0279f,
		0.03188f,
		0.03586f,
		0.0398f,
		0.0438f,
		0.04776f,
		0.05172f,
		0.05567f,
		0.05966f,
		0.0636f,
		0.06749f,
		0.07142f,
		0.07535f,
		0.0793f,
		0.08317f,
		0.08706f,
		0.09095f,
		0.09483f,
		0.09871f,
		0.10257f,
		0.10642f,
		0.11026f,
		0.11409f,
		0.11791f,
		0.12172f,
		0.12552f,
		0.1293f,
		0.13307f,
		0.13683f,
		0.14058f,
		0.14431f,
		0.14803f,
		0.15173f,
		0.15542f,
		0.1591f,
		0.16276f,
		0.1664f,
		0.17003f,
		0.17364f,
		0.17724f,
		0.18082f,
		0.18439f,
		0.18793f,
		0.19146f,
		0.19497f,
		0.19847f,
		0.20194f,
		0.2054f,
		0.20884f,
		0.21226f,
		0.21566f,
		0.21904f,
		0.2224f,
		0.22575f,
		0.22907f,
		0.23237f,
		0.23565f,
		0.23891f,
		0.24215f,
		0.24537f,
		0.24857f,
		0.25175f,
		0.2549f,
		0.25804f,
		0.26115f,
		0.26424f,
		0.2673f,
		0.27035f,
		0.27337f,
		0.27637f,
		0.27935f,
		0.2823f,
		0.28524f,
		0.28814f,
		0.29103f,
		0.29389f,
		0.29673f,
		0.29955f,
		0.30234f,
		0.30511f,
		0.30785f,
		0.31057f,
		0.31327f,
		0.31594f,
		0.31859f,
		0.32121f,
		0.32381f,
		0.32639f,
		0.32894f,
		0.33147f,
		0.33398f,
		0.33646f,
		0.33891f,
		0.34134f,
		11f / 32f,
		0.34614f,
		0.34849f,
		0.35083f,
		0.35314f,
		0.35543f,
		0.35769f,
		0.35993f,
		0.36214f,
		0.36433f,
		0.3665f,
		0.36864f,
		0.37076f,
		0.37286f,
		0.37493f,
		0.37698f,
		0.379f,
		0.381f,
		0.38298f,
		0.38493f,
		0.38686f,
		0.38877f,
		0.39065f,
		0.39251f,
		0.39435f,
		0.39617f,
		0.39796f,
		0.39973f,
		0.40147f,
		0.4032f,
		0.4049f,
		0.40658f,
		0.40824f,
		0.40988f,
		0.41149f,
		0.41308f,
		0.41466f,
		0.41621f,
		0.41774f,
		0.41924f,
		0.42073f,
		0.4222f,
		0.42364f,
		0.42507f,
		0.42647f,
		0.42785f,
		0.42922f,
		0.43056f,
		0.43189f,
		0.43319f,
		0.43448f,
		0.43574f,
		0.43699f,
		0.43822f,
		0.43943f,
		0.44062f,
		0.44179f,
		0.44295f,
		0.44408f,
		0.4452f,
		0.4463f,
		0.44738f,
		0.44845f,
		0.4495f,
		0.45053f,
		0.45154f,
		0.45254f,
		0.45352f,
		0.45449f,
		0.45543f,
		0.45637f,
		0.45728f,
		0.45818f,
		0.45907f,
		0.45994f,
		0.4608f,
		0.46164f,
		0.46246f,
		0.46327f,
		0.46407f,
		0.46485f,
		0.46562f,
		0.46638f,
		0.46712f,
		0.46784f,
		0.46856f,
		0.46926f,
		0.46995f,
		0.47062f,
		0.47128f,
		0.47193f,
		0.47257f,
		0.4732f,
		0.47381f,
		0.47441f,
		0.475f,
		0.47558f,
		0.47615f,
		0.4767f,
		0.47725f,
		0.47778f,
		0.47831f,
		0.47882f,
		0.47932f,
		0.47982f,
		0.4803f,
		0.48077f,
		0.48124f,
		0.48169f,
		0.48214f,
		0.48257f,
		0.483f,
		0.48341f,
		0.48382f,
		0.48422f,
		0.48461f,
		0.485f,
		0.48537f,
		0.48574f,
		0.4861f,
		0.48645f,
		0.48679f,
		0.48713f,
		0.48745f,
		0.48778f,
		0.48809f,
		0.4884f,
		0.4887f,
		0.48899f,
		0.48928f,
		0.48956f,
		0.48983f,
		0.4901f,
		0.49036f,
		0.49061f,
		0.49086f,
		0.49111f,
		0.49134f,
		0.49158f,
		0.4918f,
		0.49202f,
		0.49224f,
		0.49245f,
		0.49266f,
		0.49286f,
		0.49305f,
		0.49324f,
		0.49343f,
		0.49361f,
		0.49379f,
		0.49396f,
		0.49413f,
		0.4943f,
		0.49446f,
		0.49461f,
		0.49477f,
		0.49492f,
		0.49506f,
		0.4952f,
		0.49534f,
		0.49547f,
		0.4956f,
		0.49573f,
		0.49585f,
		0.49598f,
		0.49609f,
		0.49621f,
		0.49632f,
		0.49643f,
		0.49653f,
		0.49664f,
		0.49674f,
		0.49683f,
		0.49693f,
		0.49702f,
		0.49711f,
		0.4972f,
		0.49728f,
		0.49736f,
		0.49744f,
		0.49752f,
		0.4976f,
		0.49767f,
		0.49774f,
		0.49781f,
		0.49788f,
		0.49795f,
		0.49801f,
		0.49807f,
		0.49813f,
		0.49819f,
		0.49825f,
		0.49831f,
		0.49836f,
		0.49841f,
		0.49846f,
		0.49851f,
		0.49856f,
		0.49861f,
		0.49865f,
		0.49869f,
		0.49874f,
		0.49878f,
		0.49882f,
		0.49886f,
		0.49889f,
		0.49893f,
		0.49896f,
		0.499f
	};

	public static float standardNormalTableCoarsnes = 0.01f;

	private static GaussDistribution _instance;

	private float? _spareValue;

	public static GaussDistribution instance
	{
		get
		{
			if (_instance == null)
			{
				_instance = new GaussDistribution();
			}
			return _instance;
		}
	}

	public static float GetStandardDeviationForProbability(float probability)
	{
		float num = Mathf.Clamp01(probability) * 0.5f;
		int num2 = 0;
		int num3 = standardNormalTable.Length - 1;
		bool flag = false;
		float[] array = standardNormalTable;
		while (num3 - num2 > 1)
		{
			int num4 = (num2 + num3) / 2;
			if (array[num4] < num)
			{
				num2 = num4;
				continue;
			}
			if (array[num4] > num)
			{
				num3 = num4;
				continue;
			}
			return (float)num4 * standardNormalTableCoarsnes;
		}
		return Mathf.Lerp((float)num2 * standardNormalTableCoarsnes, (float)num3 * standardNormalTableCoarsnes, Mathf.InverseLerp(array[num2], array[num3], num));
	}

	public float Next()
	{
		float? spareValue = _spareValue;
		if (spareValue.HasValue)
		{
			float value = _spareValue.Value;
			_spareValue = null;
			return value;
		}
		float num;
		float num2;
		float num3;
		do
		{
			num = 2f * UnityEngine.Random.Range(0f, 1f) - 1f;
			num2 = 2f * UnityEngine.Random.Range(0f, 1f) - 1f;
			num3 = num * num + num2 * num2;
		}
		while ((double)num3 > 1.0 || num3 == 0f);
		float num4 = Mathf.Sqrt(-2f * Mathf.Log(num3, (float)Math.E) / num3);
		_spareValue = num * num4;
		return num2 * num4;
	}

	public float Next(float mu, float sigma)
	{
		return mu + Next() * sigma;
	}

	public bool getDecissionWithSuccess(float success)
	{
		if (Mathf.Abs(success) == 0f)
		{
			return false;
		}
		success = Mathf.Clamp01(success);
		Mathf.Clamp01(success);
		float num = Mathf.Abs(Next(0f, 1f));
		float standardDeviationForProbability = GetStandardDeviationForProbability(success);
		return num < standardDeviationForProbability;
	}
}
